package com.example.mq.comfig;

import com.example.commonutils.constants.MqConstants;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    //交换机
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(MqConstants.ARTICLE_EXCHANGE,true,false);
    }
    //新增和修改队列
    @Bean
    public Queue insertQueue(){
        return new Queue(MqConstants.ARTICLE_INSERT_QUEUE,true);
    }
    //删除队列
    @Bean
    public Queue deleteQueue(){
        return new Queue(MqConstants.ARTICLE_DELETE_QUEUE,true);
    }
    //做绑定
    @Bean
    public Binding insertQueueBinding(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstants.ARTICLE_INSERT_KEY);
    }
    @Bean
    public Binding deleteQueueBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.ARTICLE_DELETE_KEY);
    }

    //交换机
    @Bean
    public TopicExchange LearnTopicExchange(){
        return new TopicExchange(MqConstants.LEARN_EXCHANGE,true,false);
    }
    //新增和修改队列
    @Bean
    public Queue LearnInsertQueue(){
        return new Queue(MqConstants.LEARN_INSERT_QUEUE,true);
    }
    //删除队列
    @Bean
    public Queue LearnDeleteQueue(){
        return new Queue(MqConstants.LEARN_DELETE_QUEUE,true);
    }
    //做绑定
    @Bean
    public Binding LearnInsertQueueBinding(){
        return BindingBuilder.bind(insertQueue()).to(topicExchange()).with(MqConstants.LEARN_INSERT_KEY);
    }
    @Bean
    public Binding LearnDeleteQueueBinding(){
        return BindingBuilder.bind(deleteQueue()).to(topicExchange()).with(MqConstants.LEARN_DELETE_KEY);
    }
}
